<?php

class Loader 
{
	protected $path;

	protected $files;

	protected $loaded = false;

	public function __construct($path) {
		$this->path = $path;
	}

	public function load()
	{
		if ( $this->loaded ) 
		{
			return ;
		}

		$files = glob($this->path."/*.md");
		if ( FALSE === $files ) 
		{
			//trigger_error
			return;
		}
		elseif ( empty($files) ) 
		{
			return $files;
		}
		$path = $this->path;
		$this->files = array_map(function($file) use($path) {
			$path = "/". trim($path, "/") ."/";
			return str_replace($path, "", $file);
		}, $files);
		$this->loaded = true;
	}

	public function files($files = array())
	{
		if ( $files ) 
		{
			$this->files = $files;
		}
		return $this->files;
	}

	public function get_content($file)
	{
		$fullpath = $this->path ."/". $file;

		return file_get_contents($fullpath);
	}

	public function setPath($path)
	{
		$this->path = $path;
	}

	public function getPath()
	{
		return $path;
	}
}